<html>
<head><meta charset="utf-8"><title>Compiling rustc for MingW host on Linux · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compiling.20rustc.20for.20MingW.20host.20on.20Linux.html">Compiling rustc for MingW host on Linux</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="235373633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compiling%20rustc%20for%20MingW%20host%20on%20Linux/near/235373633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> weltling <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compiling.20rustc.20for.20MingW.20host.20on.20Linux.html#235373633">(Apr 20 2021 at 16:28)</a>:</h4>
<p>Hi,</p>
<p>I'm compiling rustc 1.51.0 on Ubuntu 18.04 and the config.toml contains</p>
<div class="codehilite"><pre><span></span><code>target = [&quot;aarch64-unknown-linux-gnu&quot;, &quot;x86_64-pc-windows-gnu&quot;]
host = [&quot;x86_64-pc-windows-gnu&quot;]
build = &quot;x86_64-unknown-linux-gnu&quot;
</code></pre></div>
<p>With this, my goal is to  produce a cross compiler that could be executed on Windows natively, use GNU toolchain and produce ARM64 binaries.</p>
<p>At some point, it wants to rebuild LLVM and dies with</p>
<div class="codehilite"><pre><span></span><code>/usr/bin/x86_64-w64-mingw32-g++  -DGTEST_HAS_RTTI=0 -D_FILE_OFFSET_BITS=64 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Support -I/repo/rust/src/llvm-project/llvm/lib/Support -Iinclude
-I/repo/rust/src/llvm-project/llvm/include -ffunction-sections -fdata-sections -m64 -Wa,-mbig-obj -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment  -O2 -DNDEBUG   -std=c++14  -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/CodeGenCoverage.cpp.obj -MF lib/Support/CMakeFiles/LLVMSupport.dir/CodeGenCoverage.cpp.obj.d -o lib/Support/CMakeFiles/LLVMSupport.dir/CodeGenCoverage.cpp.obj -c /repo/rust/src/llvm-project/llvm/lib/Support/CodeGenCoverage.cpp
In file included from /repo/rust/src/llvm-project/llvm/lib/Support/CodeGenCoverage.cpp:17:0:
/repo/rust/src/llvm-project/llvm/include/llvm/Support/Mutex.h:29:12: error: ‘recursive_mutex’ in namespace ‘std’ does not name a type
       std::recursive_mutex impl;
            ^~~~~~~~~~~~~~~
/repo/rust/src/llvm-project/llvm/include/llvm/Support/Mutex.h: In member function ‘bool llvm::sys::SmartMutex&lt;mt_only&gt;::lock()’:
/repo/rust/src/llvm-project/llvm/include/llvm/Support/Mutex.h:35:11: error: ‘impl’ was not declared in this scope
           impl.lock();
</code></pre></div>
<p>I'd appreciate any help understanding and fixing this. I've also seen there's rust-mingw, but  i don't seem to find any documentation on how to build or use it, maybe that would be the correct way.</p>
<p>Thanks!</p>



<a name="235374071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compiling%20rustc%20for%20MingW%20host%20on%20Linux/near/235374071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compiling.20rustc.20for.20MingW.20host.20on.20Linux.html#235374071">(Apr 20 2021 at 16:31)</a>:</h4>
<p>What does <code>/usr/bin/x86_64-w64-mingw32-g++ -v</code> give as version?</p>



<a name="235374425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compiling%20rustc%20for%20MingW%20host%20on%20Linux/near/235374425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> weltling <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compiling.20rustc.20for.20MingW.20host.20on.20Linux.html#235374425">(Apr 20 2021 at 16:33)</a>:</h4>
<div class="codehilite"><pre><span></span><code>$ /usr/bin/x86_64-w64-mingw32-g++ --version
x86_64-w64-mingw32-g++ (GCC) 7.3-win32 20180312
</code></pre></div>



<a name="235374793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compiling%20rustc%20for%20MingW%20host%20on%20Linux/near/235374793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> weltling <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compiling.20rustc.20for.20MingW.20host.20on.20Linux.html#235374793">(Apr 20 2021 at 16:35)</a>:</h4>
<p>The regular one is </p>
<div class="codehilite"><pre><span></span><code>gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
</code></pre></div>



<a name="235375859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compiling%20rustc%20for%20MingW%20host%20on%20Linux/near/235375859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compiling.20rustc.20for.20MingW.20host.20on.20Linux.html#235375859">(Apr 20 2021 at 16:42)</a>:</h4>
<p>It seems to be new enough.</p>



<a name="235377630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compiling%20rustc%20for%20MingW%20host%20on%20Linux/near/235377630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> weltling <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compiling.20rustc.20for.20MingW.20host.20on.20Linux.html#235377630">(Apr 20 2021 at 16:54)</a>:</h4>
<p>The point is also - the regular <code>gcc</code> builds that fine, but MingW fails. Maybe that is what happens.</p>
<p>Thanks</p>



<a name="235382486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compiling%20rustc%20for%20MingW%20host%20on%20Linux/near/235382486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> weltling <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compiling.20rustc.20for.20MingW.20host.20on.20Linux.html#235382486">(Apr 20 2021 at 17:27)</a>:</h4>
<p>I now also tried to use the system LLVM by adding for all targets things like:</p>
<div class="codehilite"><pre><span></span><code>[target.x86_64-unknown-linux-gnu]
llvm-config = &quot;/usr/bin/llvm-config-10&quot;
</code></pre></div>
<p>And attaching <code>--llvm-skip-rebuild</code> to the command:</p>
<p><code>python3 src/bootstrap/bootstrap.py build --stage 2 -j24 --verbose --llvm-skip-rebuild TRUE</code></p>
<p>There is another error,  but apparently it still tries to rebuild LLVM for host:</p>
<div class="codehilite"><pre><span></span><code>running: &quot;x86_64-w64-mingw32-g++&quot; &quot;-O3&quot; &quot;-ffunction-sections&quot; &quot;-fdata-sections&quot; &quot;-m64&quot; &quot;-ffunction-sections&quot; &quot;-fdata-sections&quot; &quot;-m64&quot; &quot;-I/usr/lib/llvm-10/include&quot; &quot;-std=c++14&quot; &quot;-fno-exceptions&quot; &quot;-D_GNU_SOURCE&quot; &quot;-D__STDC_CONSTANT_MACROS&quot; &quot;-D__STDC_FORMAT_MACROS&quot; &quot;-D__STDC_LIMIT_MACROS&quot; &quot;-DLLVM_COMPONENT_AARCH64&quot; &quot;-DLLVM_COMPONENT_AMDGPU&quot; &quot;-DLLVM_COMPONENT_ARM&quot; &quot;-DLLVM_COMPONENT_ASMPARSER&quot; &quot;-DLLVM_COMPONENT_AVR&quot; &quot;-DLLVM_COMPONENT_BITREADER&quot; &quot;-DLLVM_COMPONENT_BITWRITER&quot; &quot;-DLLVM_COMPONENT_COVERAGE&quot; &quot;-DLLVM_COMPONENT_HEXAGON&quot; &quot;-DLLVM_COMPONENT_INSTRUMENTATION&quot; &quot;-DLLVM_COMPONENT_IPO&quot; &quot;-DLLVM_COMPONENT_LINKER&quot; &quot;-DLLVM_COMPONENT_LTO&quot; &quot;-DLLVM_COMPONENT_MIPS&quot; &quot;-DLLVM_COMPONENT_MSP430&quot; &quot;-DLLVM_COMPONENT_NVPTX&quot; &quot;-DLLVM_COMPONENT_POWERPC&quot; &quot;-DLLVM_COMPONENT_RISCV&quot; &quot;-DLLVM_COMPONENT_SPARC&quot; &quot;-DLLVM_COMPONENT_SYSTEMZ&quot; &quot;-DLLVM_COMPONENT_WEBASSEMBLY&quot; &quot;-DLLVM_COMPONENT_X86&quot; &quot;-DNDEBUG&quot; &quot;-o&quot; &quot;/repo/rust/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-pc-windows-gnu/release/build/rustc_llvm-09ac7aac62567d42/out/llvm-wrapper/PassWrapper.o&quot; &quot;-c&quot; &quot;llvm-wrapper/PassWrapper.cpp&quot;
  cargo:warning=In file included from /usr/lib/llvm-10/include/llvm/Support/VirtualFileSystem.h:25:0,
  cargo:warning=                 from /usr/lib/llvm-10/include/llvm/Support/CommandLine.h:34,
  cargo:warning=                 from llvm-wrapper/LLVMWrapper.h:14,
  cargo:warning=                 from llvm-wrapper/PassWrapper.cpp:6:
  cargo:warning=/usr/lib/llvm-10/include/llvm/Support/FileSystem.h:164:3: error: ‘uid_t’ does not name a type; did you mean ‘pid_t’?
  cargo:warning=   uid_t fs_st_uid = 0;
  cargo:warning=   ^~~~~
</code></pre></div>
<p>At this point - perhaps someone could also point to the build scripts used for the official build? That might help to learn and replicate that setup.</p>
<p>Thanks!</p>



<a name="235383570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compiling%20rustc%20for%20MingW%20host%20on%20Linux/near/235383570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compiling.20rustc.20for.20MingW.20host.20on.20Linux.html#235383570">(Apr 20 2021 at 17:34)</a>:</h4>
<p>You need to use <code>[target.x86_64-pc-windows-gnu]</code> here instead of <code>[target.x86_64-unknown-linux-gnu]</code>.</p>



<a name="235384230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compiling%20rustc%20for%20MingW%20host%20on%20Linux/near/235384230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> weltling <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compiling.20rustc.20for.20MingW.20host.20on.20Linux.html#235384230">(Apr 20 2021 at 17:38)</a>:</h4>
<p>Yeah, i actually used it for all of them. My current <code>config.toml</code>, should have posted it in the initial post:</p>
<div class="codehilite"><pre><span></span><code>changelog-seen = 2

[target.aarch64-unknown-linux-gnu]
llvm-config = &quot;/usr/bin/llvm-config-10&quot;

[target.x86_64-pc-windows-gnu]
llvm-config = &quot;/usr/bin/llvm-config-10&quot;

[target.x86_64-unknown-linux-gnu]
llvm-config = &quot;/usr/bin/llvm-config-10&quot;

[rust]
rpath = true
channel = &quot;stable&quot;
optimize = true

[build]
submodules = false
docs = false
vendor = true
target = [&quot;aarch64-unknown-linux-gnu&quot;, &quot;x86_64-pc-windows-gnu&quot;]
host = [&quot;x86_64-pc-windows-gnu&quot;]
build = &quot;x86_64-unknown-linux-gnu&quot;
</code></pre></div>
<p>Thanks</p>



<a name="239926151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Compiling%20rustc%20for%20MingW%20host%20on%20Linux/near/239926151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> jam1garner <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Compiling.20rustc.20for.20MingW.20host.20on.20Linux.html#239926151">(May 23 2021 at 05:38)</a>:</h4>
<p><span class="user-mention" data-user-id="395246">@weltling</span> I've been working on something rather similar recently (also cross compiling linux -&gt; windows for producing a compiler that can target aarch64, what are the odds :P), the fix is actually rather simple! The problem is that by default mingw uses <code>x86_64-w64-mingw32-g++-win32</code>, which does not have pthreads support (and afaik MinGW without pthreads doesn't have std::mutex implemented currently). In order to fix this on debian systems you can use the following commands:</p>
<div class="codehilite"><pre><span></span><code>sudo update-alternatives --config x86_64-w64-mingw32-g++
sudo update-alternatives --config x86_64-w64-mingw32-gcc
sudo update-alternatives --config i686-w64-mingw32-g++
sudo update-alternatives --config i686-w64-mingw32-gcc
</code></pre></div>
<p>and for each one select the option that ends in <code>-posix</code>. For example <code>x86_64-w64-mingw32-g++</code> has <code>/usr/bin/x86_64-w64-mingw32-g++-posix</code> as an option.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>